<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>异步请求</title>
    <script src="js/createXMLHttpRequest对象.js"></script>
</head>
<body>
    <form action="#">
        <input type="text" name="user">
        <input type="text" name="pwd">
        <input type="submit">
    </form>
    <button class="btn">按钮</button>
    <script>
        var btn = document.getElementsByClassName("btn")[0]
        console.log(btn)
        btn.addEventListener('click',function(){
            var xhr = createXMLHttpRequest();
            console.log(xhr)
            xhr.open('get',"http://127.0.0.1:3000")
            xhr.send(null)
            // 设置请求头信息
            // xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xhr.onreadystatechange = function(){
                if (xhr.readState === 4){
                    if (xhr.status === 200){
                        console.log(xhr.responseText)
                    }
                }
            }
        })
    </script>
</body>
</html>